package org.aeon.gamechatnest.common.response;

import lombok.Getter;

import java.util.Arrays;
import java.util.HashMap;

/**
 * @author: MissingAeon
 * @date: 2024/4/18 14:30
 * @description:
 */
@Getter
public enum RespStatus {
    SUCCESS(100, "success"),

    MESSAGE_SENT_SUCCESSFULLY(120, "消息发送成功"),
    MESSAGE_RECEIVED_SUCCESSFULLY(121, "消息接收成功"),
    MESSAGE_SYNCHRONIZATION_SUCCESSFUL(122, "消息同步成功"),

    // 失败
    FAIL(200, "fail"),
    // FAIL(200, "fail"),

    // 错误
    ERROR(300, "error"),
    DUPLICATE_KEY_ERROR(301, "数据重复，请检查后提交"),
    PARAM_ERROR(302, "参数错误"),
    VALIDATION_ERROR(303, "验证错误"),
    CONSTRAINT_ERROR(304, "约束错误"),
    BIND_ERROR(305, "绑定错误"),

    REQUEST_METHOD_ERROR(306, "请求方法错误"),
    NO_HANDLER_FOUND_ERROR(307, "未找到处理该请求程序"),
    AUTHENTICATION_ERROR(308, "身份验证失败！请重新登录！"),
    TOKEN_ERROR(309, "token不存在或者过期"),
    TOKEN_FORMAT_ERROR(310, "token格式错误"),
    NO_PERMISSION(311, "无权限，请联系管理员"),
    NOT_FOUND(312, "请求的数据不存在"),

    MESSAGE_SENT_FAILED(320, "消息发送失败"),
    TARGET_CONVERSATION_NOT_FOUND_ERROR(321, "目标对话不存在错误"),
    NO_ACCESS_PERMISSION_TO_TARGET_CONVERSATION(321, "无权限访问目标对话"),
    ;
    private static final HashMap<Object, Object> respStatusMap;

    static {
        respStatusMap = new HashMap<>();
        Arrays.stream(RespStatus.values()).forEach(respStatus -> respStatusMap.put(respStatus.getCode(), respStatus));
    }

    private final Integer code;
    private final String message;

    RespStatus(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static RespStatus find(Integer code) {
        return (RespStatus) respStatusMap.get(code);
    }
}
